/*
 * MockController.java
 *
 * Created on 13 de marzo de 2008, 08:34
 *
 */

package org.gbuela.avant.testing;

import org.gbuela.avant.Command;
import org.gbuela.avant.CommandContext;
import org.gbuela.avant.Request;
import org.gbuela.avant.util.CommandClassTranslator;

/**
 *
 * @author gbuela
 */
public class MockController
{
    private MockRequest request = new MockRequest();
    private CommandClassTranslator translator = new CommandClassTranslator();
    private String commandPackage;
    private String commandSuffix;
    private String contextPath;
    private String requestURL;
    
    /** Creates a new instance of MockController */
    public MockController()
    {
    }
    
    public MockController(String pkg, String suffix)
    {
        commandPackage = pkg;
        commandSuffix = suffix;
    }

    public MockController(String pkg, String suffix, String contextPath, String url)
    {
        this(pkg, suffix);
        this.contextPath = contextPath;
        this.requestURL = url;
        this.request = new MockRequest(contextPath, url);
    }
    
    public CommandContext go(Command command)
    {
        translator.setCommandSuffix(commandSuffix);
        translator.setPackageName(commandPackage);
        
        CommandContext context = new CommandContext(request, translator);
        command.execute(context);
        return context;
    }

    public MockRequest getRequest()
    {
        return request;
    }

    public void setRequest(MockRequest request)
    {
        this.request = request;
    }
    
    
}
